package main

import (
	"fmt"
)

type Integer int

func main() {
	fmt.Println(deferFun())
	fmt.Println(deferFun1())
	fmt.Println(deferFun2())
	fmt.Println(deferFun3())
	fmt.Println(deferFun4())
	fmt.Println(deferFun5())

	var a Integer = 1
	var b Integer = 2
	var i interface{} = &a
	sum := i.(*Integer).Add(b)
	fmt.Println(sum)
}

func (a Integer) Add(b Integer) int {
	intA := int(a)
	intB := int(b)
	return intA + intB
}

func deferFun() (a, b, c int) {
	a, b, c = 1, 2, 3
	defer func() {
		a, b, c = 4, 5, 6
	}()
	return
}

func deferFun1() (a, b, c int) {
	a, b, c = 1, 2, 3
	defer func(a, b, c int) {
		a, b, c = 4, 5, 6
	}(a, b, c)
	return
}

func deferFun2() (a, b, c int) {
	a, b, c = 1, 2, 3
	defer func(a, b, c *int) {
		*a, *b, *c = 4, 5, 6
	}(&a, &b, &c)
	return
}

func deferFun3() (int, int, int) {
	a, b, c := 1, 2, 3
	defer func() {
		a, b, c = 4, 5, 6
	}()
	return a, b, c
}

func deferFun4() (int, int, int) {
	a, b, c := 1, 2, 3
	defer func(a, b, c int) {
		a, b, c = 4, 5, 6
	}(a, b, c)
	return a, b, c
}
func deferFun5() (int, int, int) {
	a, b, c := 1, 2, 3
	defer func(a, b, c *int) {
		*a, *b, *c = 4, 5, 6
	}(&a, &b, &c)
	return a, b, c
}
